home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / misc / sci / RARS_Amiga_2.lha / RARS / report.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  2.4 KB  |  100 lines

  1. // REPORT.CPP - output of racing and other data to a file - M. Timin, March 1995
  2. // for RARS version 0.4
  3.  
  4. /*
  5.  * Modified:
  6.  *
  7.  * - l. 54 : Added typecast to remove warning that char != int.
  8.  */
  9.  
  10. #include <fstream.h>
  11. #include <iostream.h>
  12. #include <string.h>
  13. #include <iomanip.h>
  14. #include "track.h"
  15. #include "car.h"
  16.  
  17. ofstream fout("race.out");
  18.  
  19. extern char* nam_ptr[];     // The original array of robot names
  20.  
  21. static int how_many;
  22.  
  23. int find_name(char* name)  // find this name in original array, nam_ptr
  24. {
  25.  
  26.    int i, cmp;
  27.    for(i=0; i<MAXCARS; i++) {
  28.       cmp = strcmp(name, nam_ptr[i]);
  29.       if(!cmp)
  30.          break;
  31.    }
  32.    if(i == MAXCARS)
  33.       return -1;              // -1 is returned if name is not found,
  34.    else
  35.       return i;               // else returned value will be 0 - 15
  36. }
  37.  
  38. /* there is no help file on the Amiga version */
  39. void print_help_file(void)
  40. {
  41.     return;
  42. }
  43.  
  44. /* the ram reporting function was very silly, so I removed it altogether */
  45. void RAM_report(void)
  46. {
  47.     return;
  48. }
  49.  
  50. void output_names(int cars, char** names)
  51. {
  52.    for(int i=0; i<cars; i++) {
  53.       if(i < cars - 1)  {
  54.          fout << names[i] << ", ";
  55.          if(i == 7)
  56.             fout << endl;
  57.       }
  58.       else
  59.          fout << "and " << names[i] << "." << endl;
  60.    }
  61. }
  62.  
  63. void report_overall(int cars, int laps, char** names)
  64. {
  65.    how_many = cars;   // store the car count for later use
  66.  
  67.    fout << cars << " cars for " << laps << " laps.  The track was ";
  68.    fout << trackfile << ".  The drivers were:" << endl;
  69.    output_names(cars, names);
  70.    fout << endl;
  71. }
  72.  
  73. void report_results(int race, int* order, char** names, Car** pcar)
  74. {
  75.    int i, k, m, who;
  76.    const int points[] = { 10, 6, 4, 3, 2, 1 };
  77.    static int accum_pts[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  78.  
  79.    fout << "   results of race " << race << ":" << endl;
  80.    fout << "starting positions:" << endl;
  81.  
  82.    output_names(how_many, names);
  83.  
  84.    // The places:
  85.    m = how_many;
  86.    for(i=0; i<m; i++) {
  87.       k = order[i];
  88.       who = find_name(names[k]); // Where is the kth car in the original list?
  89.       if(i < 6)
  90.          accum_pts[who] += points[i];
  91.       fout << "place " << i+1 << "  ";
  92.       fout << setw(10) << setiosflags(ios::left) << names[k];
  93.       fout << setprecision(2);
  94.       fout << " average speed " << pcar[k]->speed_avg * MPH_FPS;
  95.       fout << " mph" << "   " << accum_pts[who];
  96.       fout << " points accumulated" << endl;
  97.    }
  98.    fout << endl;
  99. }
  100.